/*
 * Login.cpp
 *
 *  Created on: 18/11/2013
 *      Author: fernando
 */

#include "Login.h"



const unsigned int WIDTHINICIAL= 424;
const unsigned int HEIGTHINICIAL = 224;
const unsigned int WIDHTLOG = 400;
const unsigned int HEIGHTLOG = 248;

Login::Login(){
	ancho = WIDTHINICIAL;
	alto = HEIGTHINICIAL;
	ingresaUsuario = true;
	opcion = true;
	pantallaInicial = true;
}

Login::~Login() {
	SDL_FreeSurface(fondo);
}


void Login::ubicarMouse(unsigned int x, unsigned int y){
	posXMouse = x;
	posYMouse = y;
}

void Login::logInit(){
	init("Login");
	fondo = load_image("trunk/Imagenes/PantallaInicial.png");
}

void Login::dibujar(){
	apply_surface(0,0, fondo, screen, NULL);
	if (!pantallaInicial){
		user.show(205, 40, screen);
		pass.showHidden(205, 105, screen);
	}
//		fondo = load_image("trunk/Imagenes/PantallaInicial.png");
	SDL_Flip(screen);
}

void Login::handleInput(SDL_Event& event){
    if(event.key.keysym.sym == SDLK_TAB){
        ingresaUsuario = !ingresaUsuario;
    }else{
		if (ingresaUsuario){
			user.handle_input(event);
		}else{
			pass.handle_input(event);
		}
    }
}

void Login::setIngresaUsuario(){
	if (posXMouse < 380 && posXMouse > 205){
		if (posYMouse > 30){
			if (posYMouse < 75){
				ingresaUsuario = true;
			}else if (posYMouse > 90 && posYMouse < 135){
				ingresaUsuario = false;
			}
		}
	}
}

void Login::handleClick(){
	if (pantallaInicial){
		setIngresaOpcion();
	}else{
		setIngresaUsuario();
	}
}

void Login::setIngresaOpcion(){
	if (posYMouse > 90 && posYMouse < 170 ){
		if (posXMouse > 30 && posXMouse < 190){
			opcion = true;
			pasarALogin();
		}else if(posXMouse > 220 && posXMouse < 380){
			opcion =false;
			pasarALogin();
		}
	}
}

void Login::pasarALogin(){
	fondo = load_image("trunk/Imagenes/Login.png");
	pantallaInicial = false;
}




